package com.pubinfo.passbook.engine.cell.logic.medicine;

import com.pubinfo.passbook.common.model.constant.StaffStatusEnum;
import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.dubbo.ESBServiceData;
import com.pubinfo.passbook.common.model.http.engine.ComputeParamSlot;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.dubbo.DubboService;
import com.pubinfo.passbook.common.service.ruler.InformationService;
import com.pubinfo.passbook.engine.constants.ComputeResultType;
import com.pubinfo.passbook.engine.utils.ApplicationContextUilts;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * 工龄小于 max
 *
 * @author zhouch
 * @date 2022/1/19 14:25
 */
public class WorkAgeLessUnit extends MedicineLogicUnit {

    private static final ComputeParamSlot MAX_WORK_AGE_PARAM_SLOT = ComputeParamSlot.of("max", ComputeResultType.NUMBER);

    DubboService dubboService;

    public WorkAgeLessUnit() {
        dubboService = ApplicationContextUilts.getBean(DubboService.class);
    }


    @Override
    public Collection<ComputeParamSlot> getParamSlots() {
        return Arrays.asList(
                MAX_WORK_AGE_PARAM_SLOT
        );
    }

    @Override
    public Boolean then(MedicineOnJobOrRetireDTO data, BigDecimal result) {
        List<PayInformation> payInformations = cache.getPayInformationData();

        //报账人的身份证号
        String idNo = payInformations.get(0).getPayerPartyCode();

        ESBServiceData.CertDetail certDetail = dubboService.getPersonsDetailByIdNo(idNo);

        //工龄
        int lengthOfService = Integer.parseInt(certDetail.getWorkTime());

        //工作状态   0：退休  1：在职/内退  2:离休
        Integer working = StaffStatusEnum.getEnumByStatus(certDetail.getStaffStatus()).getCode();

        int max = getParamenter(data, MAX_WORK_AGE_PARAM_SLOT.getName()).intValue();

        return lengthOfService < max;
    }

    @Override
    public String getName() {
        return "工龄是否小于("
                + getParamenter(cache.getMedicineData(), MAX_WORK_AGE_PARAM_SLOT.getName()).intValue()
                + ")";
    }
}
